package com.google.code.task.example;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.google.code.task.TaskResultType;
import com.google.code.task.example.resources.NullPointerExceptionTask;

import static com.google.code.task.Style.*;

public class TryCatchDecoratorExample {
  private static final Log LOG = LogFactory.getLog(TryCatchDecoratorExample.class);
  
  public static void main(String[] args) {
    startTask();
    TaskResultType result = 
      new NullPointerExceptionTask()
        .trycatch().loggable(true).resultWhenFailed(TaskResultType.FAILURE)
      .execute();
    endTask();
    LOG.info(result);

    startTask();
    result = 
    tryCatch(
        task(new NullPointerExceptionTask()), 
        loggable(true), 
        throwable(true),
        resultWhenFailed(TaskResultType.FAILOVER)
    ).execute();
    endTask();
    LOG.info(result);
  }
}
